﻿using IBLl;
using IDAL;
using Model;

namespace bll
{
    public class fanghaobll : ifanghaobll
    {
        public fanghaobll(IbaseDAL<fanghaoModel> dal)
        {
            Dal = dal;
        }

        public IbaseDAL<fanghaoModel> Dal { get; }

        public async Task<int> AddRnagefanghoa(List<fanghaoModel> fanghao)
        {
            return await Dal.AddRangeAsync(fanghao);
        }

        public List<fanghaoModel> daochu()
        {
            return Dal.GetAll().ToList();
        }

        public dynamic xianshi(int pageindex, int pagesize)
        {
            var fanghao = Dal.GetAll().ToList();

            var rph = from a in fanghao
                      select new
                      {
                          a.id,
                          a.name,
                          a.age,
                          a.phone,
                          a.dizhi,
                          a.sex
                      };

            var count=rph.Count();  
            var list=rph.OrderBy(x => x.id).Skip((pageindex-1)*pagesize).Take(pagesize).ToList();
            return new
            {
                count = count,
                list = list
            };
        }
    }
}
